package ch.fusun.baron.turn;

import java.util.Map;

import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.core.rmi.User;
import ch.fusun.baron.data.DataUpdate;

/**
 * Data update for user turn
 */
public class UserTurnDataUpdate implements DataUpdate {

	@Inject
	private transient UserTurnService userTurnService;

	private Map<User, Integer> userTurnPoints;

	/**
	 * Injection constructor
	 */
	public UserTurnDataUpdate() {
		// for injection
	}

	/**
	 * @param userTurnPoints
	 *            all the turns for all users
	 */
	public UserTurnDataUpdate(Map<User, Integer> userTurnPoints) {
		this.userTurnPoints = userTurnPoints;
	}

	@Override
	public void update() {
		for (User user : userTurnPoints.keySet()) {
			userTurnService.setPoints(user, userTurnPoints.get(user));
		}
	}
}
